const mysql = require('mysql')

const { MYSQL_CONFIG } = require('../config/db')
const connection = mysql.createConnection(MYSQL_CONFIG);
connection.connect((err) => {
    if (err) {
        throw err
    }
    console.log('数据库连接成功')
});


function execSQL(sql) {
    const promise = new Promise((resolve, rej) => {
        connection.query(sql, (err, res) => {
            if (err) {
                rej(err)
                console.log('err', err)
            }
            resolve(res)
        })
    })
    return promise

}
module.exports = {
    execSQL
}